<?php

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import the Joomla modellist library
jimport('joomla.application.component.modellist');

/**
 * AdminInterfaces Model
 */
class WelliVermittlungModelTest extends JModelList
{

    /**
     * Method to build an SQL query to load the list data.
     *
     * @return      string  An SQL query
     */
    protected function getListQuery()
    {
// http://localhost/joomla3/index.php?option=com_wellivermittlung&view=test
        
        // Create a new query object.
        $db = JFactory::getDBO();
        $query = $db->getQuery(true);

/***************************************************************************
 * Select fields of tieraerzte                                             *
 ***************************************************************************/        

//        $query->select('id,name,name2');
//        $query->from('#__wellivermittlung_tieraerzte');

        
        
/***************************************************************************
 * Select fields of tiere                                                  *
 ***************************************************************************/        

// both selects work.
//        $query->select('id,Name,GeschlechtId');
//        $query->select('*');
//        $query->from('#__wellivermittlung_tiere');
        
// does not work. why?
//        $query
//                ->select($db->quoteName(array('a.*', 'id')))
//                ->from($db->quoteName('#__wellivermittlung_tiere', 'a'));
// error message:
// Unknown column 'a.*' in 'field list' SQL=SELECT `a`.`*`,`id` FROM `jos_wellivermittlung_tiere` AS `a` LIMIT 0, 20
        
// works
//        $query
//                ->select($db->quoteName(array('a.id','a.Name','a.GeschlechtId')))
//                ->from($db->quoteName('#__wellivermittlung_tiere', 'a'));

// trying to do a join select aaaand ...
// works perfectly :D
        $query
                ->select($db->quoteName(array('a.id','a.Name','a.GeschlechtId','b.Geschlecht')))
                ->from($db->quoteName('#__wellivermittlung_tiere', 'a'))
                ->join('LEFT', $db->quoteName('#__wellivermittlung_tiergeschlecht', 'b') . ' ON (' . $db->quoteName('a.GeschlechtId') . ' = ' . $db->quoteName('b.id') . ')');
        
// dump query string for debugging purposes
        echo $query->dump();

        return $query;
    }

}
